#ifndef GRAPHTEST_H
#define GRAPHTEST_H

#include "igraph.h"
#include "graph.h"
#include "depthfirstsearch.h"
#include "breadthfirstsearch.h"
#include "connectedcomponents.h"
#include "graphtopologicalsort.h"

namespace sk {

class GraphTest : public QObject {
    Q_OBJECT

public:
    GraphTest(QObject *parent = 0) : QObject(parent) {}

    void testDepthFirstSearch() {
        CGraph graph;
        graph.init(4);
        graph.addEdge(1, 2);
        graph.addEdge(1, 3);
        graph.addEdge(2, 4);
        graph.addEdge(3, 4);

        DepthFirstSearch* dfs = new DepthFirstSearch(&graph, 1);
        dfs->go();
        dfs->debug_toString();
        delete dfs;

        printf("---\n");

        graph.init(4);
        graph.addEdge(1, 2);
        graph.addEdge(2, 3);
        graph.addEdge(3, 1);
        dfs = new DepthFirstSearch(&graph, 2);
        dfs->go();
        dfs->debug_toString();
        delete dfs;

        printf("---\n");
    }

    void testBreadthSearch() {
        CGraph graph;

        graph.init(4);
        graph.addEdge(1, 2);
        graph.addEdge(1, 3);
        graph.addEdge(2, 4);
        graph.addEdge(3, 4);

        BreadthFirstSearch* bfs = new BreadthFirstSearch(&graph, 1);
        bfs->go();
        bfs->debug_toString();
        delete bfs;

        printf("---\n");
    }

    void testTopologicalSort() {
        CGraph graph;

        graph.init(4);
        graph.addEdge(1, 2);
        graph.addEdge(1, 3);
        graph.addEdge(2, 4);
        graph.addEdge(3, 4);

        GraphTopologicalSort gts(&graph, 1);
        while(!gts.getStack().isEmpty()) {
            int i = gts.getStack().pop();
            printf("%d ", i);
        }
        printf("\n");
        printf("---\n");
    }

public slots:
    void run() {
        printf("Graph test started\n");

        //testDepthFirstSearch();
        //testBreadthSearch();
        testTopologicalSort();

        emit finished();
    }

signals:
    void finished();
};

}

#endif // GRAPHTEST_H
